<template>
  <div class="ele-body">
    <!-- 搜索表单 -->
    <profitSearch @search="reload"  />
    <!-- 搜索表单 -->
    <el-card shadow="never">
      <!-- 数据表格 -->
      <ele-pro-table
        ref="table"
        row-key="id"
        :columns="columns"
        :datasource="datasource"
        :default-expand-all="false"
        :need-page="false"
        :parse-data="parseData"
      >
        <!-- 表头工具栏 -->
        <template slot="toolbar">
          <!-- <el-button
            size="small"
            type="primary"
            icon="el-icon-plus"
            class="ele-btn-icon"
            @click="openEdit()"
          >
            添加
          </el-button> -->
          <el-button
            size="small"
            icon="el-icon-upload2"
            class="ele-btn-icon"
            @click="reportexcel"
          >
            导出
          </el-button>
        </template>
        <!-- 标题列 -->
        <template slot="title" slot-scope="{ row }">
          <i :class="row.icon"></i> {{ row.title }}
        </template>
      </ele-pro-table>
    </el-card>
    <!-- 导出数据 -->
    <ExportDialog ref="ExportDialog"></ExportDialog>
  </div>
</template>

<script>
  import moment from "moment"
  import profitSearch from './components/profit-search.vue';
  import ExportDialog from '@/components/Excel/ExportDialog'
  import { QueryProfitSummaryViewByCondition} from '@/api/statistics';

  export default {
    name: 'BrandVechile',
    components: {ExportDialog,profitSearch},
    data() {
      return {
        // 表格列配置
        columns: [
          {
            columnKey: 'index',
            type: 'index',
            width: 60,
            align: 'center',
            showOverflowTooltip: true,
            label:'序号',
          },
          // {
          //   prop: 'code',
          //   label: '编号',
          //   showOverflowTooltip: true,
          // },
          {
            prop: 'label',
            label: '名称',
            showOverflowTooltip: true,
          },
          {
            prop: 'value',
            label: '值',
            showOverflowTooltip: true,
          },
        ],
        // 当前编辑数据
        current: null,
         // 是否显示新增品牌编辑弹窗
        showEdit:false,
        // 是否显示车型编辑弹窗
        showVechileEdit:false,
        // 全部菜单数据
        menuList: [],
       
        // 导出列
        exportList: [
          { name: "名称", keys: "label", status: true },
          // { name: "编号", keys: "code", status: true },
          { name: "值", keys: "value", status: true },
        ]
      };
    },
    methods: {
      /* 表格数据源 */
      async datasource(params) {
       

        if(!params.where.sDate) params.where.sDate = moment().startOf('year').format('YYYY-01-01');
        if(!params.where.eDate) params.where.eDate = moment().endOf('year').format('YYYY-12-31');
        
        let data =await QueryProfitSummaryViewByCondition(params.where);
        this.$nextTick(() => {
          this.$refs.table.doLayout();
        });

        return data;
      },

      /* 数据转为树形结构 */
      parseData(data) {
        let treeData = this.$util.toTreeData({
          data: data,
          idField: 'id',
          parentIdField: 'parentId'
        });
        return treeData;
      },

      /* 表格渲染完成回调 */
      onDone({ data }) {
        this.menuList = data;
      },
      /* 刷新表格 */
      reload(params) {
        this.$refs.table.reload({where:params});
      },
      
     

      /* 导出 */
      async reportexcel(pams) {
        this.$refs.ExportDialog.showEdits = true
        this.$refs.ExportDialog.checkList = this.exportList
        this.$refs.ExportDialog.titleName = "利润表"
        this.$refs.ExportDialog.dataList = this.$refs.table.tableData;
      },
    
      //加载数据
      loadchildren(tree, treeNode, resolve) {
        QueryAllChildenBrandVechile(tree.id).then((res)=>{
          resolve(res);
        });
      }
    }
  };
</script>
<style lang="scss" scoped>
::v-deep .el-table__body-wrapper {
    height: 450px !important;
    overflow-y:auto !important;
  }
</style>
